GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

PagerActions.js ➔ ... ➔ ???   B
last analyzed

Complexity

Conditions 7
Paths 4

Size

Total Lines 53

Duplication

Lines 53
Ratio 100 %

Importance

Changes 0
Metric Value
cc 7
c 0
b 0
f 0
nc 4
dl 53
loc 53
rs 7.5251
nop 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
import {
2
    PAGE_LOCAL,
3
    PAGE_REMOTE,
4
    SET_DATA,
5
    ERROR_OCCURRED
6
} from '../../../constants/ActionTypes';
7
8
import { setLoaderState } from '../../../actions/plugins/loader/LoaderActions';
9
10
import { dismissEditor } from '../../../actions/plugins/editor/EditorActions';
11
12
import Api from '../../../util/api';
13
14
export const setPage = ({ index, type, BUTTON_TYPES }) => {
15
    const pageIndex = type === BUTTON_TYPES.NEXT ? index + 1 : index - 1;
16
17
    return { type: PAGE_LOCAL, pageIndex };
18
};
19
20
export const setPageIndexAsync = ({
21
    pageIndex,
22
    pageSize,
23
    dataSource,
24
    filterFields,
25
    sort,
26
    stateKey,
27
    afterAsyncFunc
28
}) => {
29
30 View Code Duplication
    if (typeof dataSource === 'function') {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if typeof dataSource === "function" is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
31
32
        return (dispatch) => {
33
34
            dispatch(dismissEditor({ stateKey }));
35
36
            dispatch(
37
                setLoaderState({ state: true, stateKey })
38
            );
39
40
            dataSource(
41
                {pageIndex, pageSize}, filterFields, sort
42
            ).then((response) => {
43
44
                if (response && response.data) {
45
46
                    dispatch({
47
                        type: PAGE_REMOTE,
48
                        pageIndex: pageIndex,
49
                        stateKey
50
                    });
51
52
                    dispatch({
53
                        type: SET_DATA,
54
                        data: response.data,
55
                        total: response.total,
56
                        currentRecords: response.items,
57
                        success: true,
58
                        stateKey
59
                    });
60
61
                    if (afterAsyncFunc
62
                        && typeof afterAsyncFunc === 'function') {
63
                        afterAsyncFunc();
64
                    }
65
                }
66
67
                else {
68
69
                    if (response && !response.data) {
70
                        /* eslint-disable no-console */
71
                        console.warn([
72
                            'A response was recieved but',
73
                            'no data entry was found'
74
                        ].join(' '));
75
                        console.warn([
76
                            'Please see',
77
                            'https://github.com/bencripps/react-redux-grid',
78
                            'for documentation'
79
                        ].join(' '));
80
                        /* eslint-enable no-console */
81
                    }
82
83
                    dispatch({
84
                        type: ERROR_OCCURRED,
85
                        error: 'Unable to Retrieve Grid Data',
86
                        errorOccurred: true,
87
                        stateKey
88
                    });
89
                }
90
91
                dispatch(
92
                    setLoaderState({ state: false, stateKey })
93
                );
94
            });
95
        };
96
    }
97
};
98
99
export const setPageAsync = ({
100
    index, pageSize, type, BUTTON_TYPES, dataSource, stateKey
101
}) => {
102
103
    const pageIndex = type === BUTTON_TYPES.NEXT ? index + 1 : index - 1;
104
105
    return (dispatch) => {
106
107
        dispatch(
108
            setLoaderState({ state: true, stateKey })
109
        );
110
111
        return Api({
112
            route: dataSource,
113
            method: 'GET',
114
            queryStringParams: {
115
                pageIndex: pageIndex,
116
                pageSize: pageSize
117
            }
118
        }).then((response) => {
119
120
            if (response && response.data) {
121
122
                dispatch({
123
                    type: PAGE_REMOTE,
124
                    pageIndex: pageIndex,
125
                    stateKey
126
                });
127
128
                dispatch({
129
                    type: SET_DATA,
130
                    data: response.data,
131
                    total: response.total,
132
                    currentRecords: response.data,
133
                    success: true,
134
                    stateKey
135
                });
136
137
                dispatch(
138
                    setLoaderState({ state: false, stateKey })
139
                );
140
            }
141
142
            else {
143
                dispatch({
144
                    type: ERROR_OCCURRED,
145
                    error: response,
146
                    errorOccurred: true,
147
                    stateKey
148
                });
149
            }
150
151
        });
152
    };
153
};
154